package com.xxx.lib.base

/**
 * Fragment二级级基类
 */
abstract class BasePresenterFragment<V : IBaseView, P : BasePresenter<V>> : BaseFragment() {

    /**
     * P层
     */
    private var presenter: P? = null

    /**
     * 创建P层
     */
    protected abstract fun createPresenter(): P

    /**
     * 获取P层
     */
    protected fun getPresenter(): P {
        if (presenter == null) {
            presenter = createPresenter()
            if (this is IBaseView) presenter?.attachView(this as V)
        }
        return presenter as P
    }

    override fun onDestroyView() {
        super.onDestroyView()
        getPresenter().detachView()
    }
}